var commonAjax = new Ajax();
function getAllCompany() {
	var allCompanyObj = commonAjax.sendAjax({
		// 2.type=select,checkSingle,checkMulti时可配置)
		url : requestPath
				+ "/system/companyOrganizations/companys/getAllCompanys", // 请求url*
		async : false, // 是否异步*
		type : "GET" // 请求类型*
	});
	return allCompanyObj;
}

function getAllCompanyOptions() {
	var allCompanyObj = getAllCompany();
	var allCompanyOptions = [];
	for (var i = 0; i < allCompanyObj.length; i++) {
		var allCompanyOption = new Object();
		allCompanyOption.value = allCompanyObj[i].id;
		allCompanyOption.text = allCompanyObj[i].name;
		allCompanyOptions.push(allCompanyOption);
	}
	return allCompanyOptions;
}

function getComMajor() {
	var comMajorObj = commonAjax.sendAjax({ // 获取用户对象
		url : requestPath + "/common/comMajors/" + sessionStorage.selectedId, // 请求url*
		async : false, // 是否异步*
		type : "GET" // 请求类型*
	});
	return comMajorObj;
}

function getMajors() {
	var majors;
	$.ajax({
		url : requestPath + "/common/comMajors/findAllMajors", // 请求url*
		async : false, // 是否异步*
		dataType : "JSON",
		type : "GET", // 请求类型*
		success : function(data) {
			majors = data;
		},
		error : function() {
			commonDialog.alertDialog(commonLocale.text.getMajorError);
		}
	});
	return majors;
}

function getMajorOptions() {
	var majors = getMajors();
	var options = [];

	for ( var i in majors) {
		var json = {};
		json.value = majors[i].id;
		json.text = majors[i].name;
		options.push(json);
	}
	return options;
}

function getComPoint() {
	var comPointObj = commonAjax.sendAjax({ // 获取用户对象
		url : requestPath + "/common/comPoints/" + sessionStorage.selectedId, // 请求url*
		async : false, // 是否异步*
		type : "GET" // 请求类型*
	});
	return comPointObj;
}

function getComUnit() {
	var comUnitObj = commonAjax.sendAjax({ // 获取用户对象
		url : requestPath + "/common/comUnits/" + sessionStorage.selectedId, // 请求url*
		async : false, // 是否异步*
		type : "GET" // 请求类型*
	});
	return comUnitObj;
}

function getUnits() {
	var units;
	$.ajax({
		url : requestPath + "/common/comUnits/findAllUnits", // 请求url*
		async : false, // 是否异步*
		dataType : "JSON",
		type : "GET", // 请求类型*
		success : function(data) {
			units = data;
		},
		error : function() {
			commonDialog.alertDialog(commonLocale.text.getUnitError);
		}
	});

	return units;
}
function findUnitById(id) {
	var units = getUnits();
	units = units.filter(function(item) {
		return item.id == id;
	});
	return units.length > 0 ? units[0] : null;
}

function getUnitOptions() {
	var units = getUnits();
	var options = [];
	for (var i = 0; i < units.length; i++) {
		var json = {};
		json.value = units[i].id;
		json.text = units[i].name;
		options.push(json);
	}
	return options;
}

/**
 * 重设表格高度
 * 
 * @param
 * @return
 */
function resetTableHeight(tableDiv, arrayDiv) {
	var leftHeight = $(".dataListDiv").height() - getTotalHeight(arrayDiv);
	$("#" + tableDiv + "").height(leftHeight);
}

/**
 * 设置窗口自适应
 * 
 * @returns
 */
function autoAdjustWindow() {
	try {
		var maxHeight = $(window.parent).height() - 70;
		var height = document.body.scrollHeight;
		var maxWidth = $(window.parent).width() - 70;
		var width = document.body.scrollWidth;
		if (height <= maxHeight) {
			window.frameElement.height = height;
			window.frameElement.style.height = height + "px";
			window.frameElement.parentElement.style.height = height + 41 + "px";
		} else {
			window.frameElement.height = maxHeight;
			window.frameElement.style.height = maxHeight + "px";
			window.frameElement.parentElement.style.height = maxHeight + 41
					+ "px";
		}
		if (width <= maxWidth) {
			window.frameElement.width = width;
			window.frameElement.style.width = width + "px";
			window.frameElement.parentElement.style.width = width + "px";
		} else {
			window.frameElement.width = maxWidth;
			window.frameElement.style.width = maxWidth + "px";
			window.frameElement.parentElement.style.width = maxWidth + "px";
		}
	} catch (e) {

	}
}